﻿using System;
using System.Collections.Generic;
using System.Linq;


namespace Sripirom.Pattern.UnitTest.Core.Domain
{
    public abstract class BaseEntity<TId>
    {
        
        public virtual TId Id { get; set; }

        /// <summary>
        /// Initializes a new instance of the EntityBaseBase class.
        /// </summary>
        public BaseEntity()
        {
            Init();
        }
        public BaseEntity(TId id)
        {
            Id = id;
            Init();
        }

        private void Init() 
        {
            //try
            //{
            //    AspFormsAuthentication formAuth = new AspFormsAuthentication();
            //    _userToken = formAuth.GetAuthenticationToken();
            //}
            //catch (Exception)
            //{

            //}
        }

 

        #region Validation

        protected abstract void Validate();

        #endregion

        #region Comparision
        public override bool Equals(object entity)
        {
            return  entity != null
                && entity is BaseEntity< TId>
                && this == (BaseEntity< TId>)entity;
        }

        public override int GetHashCode()
        {
            return Id.GetHashCode();
        }

        public  static bool operator ==(BaseEntity< TId> entity1, BaseEntity< TId> entity2)
        {
            if ((Object)entity1 == null && (Object)entity2 == null)
            {
                return true;
            }
            if ((Object)entity1 == null || (Object)entity2 == null)
            {
                return false;
            }
            if (entity1.Id.ToString() == entity2.Id.ToString())
            {
                return true;
            }
            return false;
        }

        public static bool operator !=(BaseEntity< TId> entity1,
            BaseEntity< TId> entity2)
        {
            return (!(entity1 == entity2));
        }

        #endregion



    }
}
